﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ESOL.Common.Entity;
using ESOL.Business.Mst;

namespace ESOL.WinUI.Inv
{
    public partial class frmMaintainLocationQuery : BaseForm.frmBaseDialogyQueryForm
    {
        #region Variable
        public MstLocationEntity SelectLocation { get; set; }
        public string SWareHouseCode { get; set; }
        #endregion

        #region Constructor
        public frmMaintainLocationQuery()
        {
            InitializeComponent();
            cmbWareHouseCode.SelectedValue = SWareHouseCode;
        }
        #endregion

        #region Functions
        private void BindCombobox()
        {
            List<MstWarehouseEntity> list = MstWarehouseBs.GetMstWarehouseAllList();
            cmbWareHouseCode.DataSource = list;
            MstWarehouseEntity entity = new MstWarehouseEntity();
            list.Insert(0, entity);
            cmbWareHouseCode.ValueMember = "WarehouseCode";
            cmbWareHouseCode.DisplayMember = "WarehouseName";
        }

        private string GetCondition()
        {
            string condition = "";
            if (string.IsNullOrEmpty(cmbWareHouseCode.Text) == false && cmbWareHouseCode.SelectedValue != null)
            {
                condition += " AND B.WAREHOUSE_CODE = '" + cmbWareHouseCode.SelectedValue.ToString() + "'";
            }
            if (string.IsNullOrEmpty(txtLocationcode.Text) == false)
            {
                condition += " AND A.LOCATION_CODE LIKE '%" + txtLocationcode.Text + "%'";
            }
            return condition;
        }

        private void BindDataGrid()
        {
            string sCondition = GetCondition();
            string orderBy = "B.WAREHOUSE_CODE,A.LOCATION_CODE";

            DataTable dt = MstLocationBs.GetByCondition_Code(sCondition, orderBy);
            gvMain.DataSource = dt;
        }
        #endregion


        private void frmMaintainLocationQuery_Load(object sender, EventArgs e)
        {
            BindCombobox();
            BindDataGrid();
        }
       
        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            DataRow dr = gridView1.GetDataRow(e.RowHandle);
            SelectLocation = new MstLocationEntity(dr);
        }
        protected override void Click_Query()
        {
            BindDataGrid();
        }
        protected override void Click_Confirm()
        {
            if (SelectLocation == null)
            {
                MessageBox.Show("请选择一个库位！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            if (SelectLocation == null)
            {
                MessageBox.Show("请选择一个库位！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }


    }
}